<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\SettingLoan
 *
 * @property int $id
 * @property int $blacklist_time 关进小黑屋的时间,以秒为单位
 * @property string $loan_range 借款的范围,json存储
 * @property string $period_range 借款的期限范围
 * @property int $verify_time 审核的时间,以秒为单位
 * @property int $receipt_time_one 收款的有效期1
 * @property int $receipt_time_two 收款的有效期2
 * @property int $fund_transfer_time 款项的到账时间
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\SettingLoan newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\SettingLoan newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\SettingLoan query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\SettingLoan whereBlacklistTime($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\SettingLoan whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\SettingLoan whereFundTransferTime($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\SettingLoan whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\SettingLoan whereLoanRange($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\SettingLoan wherePeriodRange($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\SettingLoan whereReceiptTimeOne($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\SettingLoan whereReceiptTimeTwo($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\SettingLoan whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\SettingLoan whereVerifyTime($value)
 * @mixin \Eloquent
 */
class SettingLoan extends Model
{
    //
    protected $guarded = ['id'];

    /**
     * 判断是否设置period_range
     */
    public static function isSetPeriodRange(){
        $info = self::select('period_range') -> first();
        if(isset($info['period_range'])){
            return $info['period_range'];
        }
        return false;
    }

    /**
     * 判断是否在period_range里面
     */
    public static function inPeriodRange($period){
        $periodRange = self::value('period_range');
        $periodRange = json_decode($periodRange,true);
        if(in_array($period,$periodRange)){
            return true;
        }else{
            return false;
        }
    }

    public static function getPeriodRange(){
        return self::value('period_range');
    }

    /**
     * 获取时效1 和 时效2
     */
    public static function getReceiptTime(){
        $result = self::select('receipt_time_one','receipt_time_two')->first()->toArray();
        $result['receipt_time_one'] = $result['receipt_time_one'] / (24*60*60);
        $result['receipt_time_two'] = $result['receipt_time_two'] / (24*60*60);
        return $result;
    }

    public static function getBlacklistTime(){
        return self::value('blacklist_time');
    }

}
